from typing import Optional
from sqlalchemy.orm import Session
from mooc.crud.crud_base import CRUDBase
from mooc.models.account import (
    AccountWechats, AccountAliapp, AccountBaiduapp,
    AccountPhoneapp, AccountToutiaoapp, Account,
    AccountWebapp, AccountWxapp, AccountXzapp
)
from mooc.schemas.account import (
    AccountWechatsCreate, AccountWechatsUpdate,
    AccountAliappCreate, AccountAliappUpdate,
    AccountBaiduappCreate, AccountBaiduappUpdate,
    AccountPhoneappCreate, AccountPhoneappUpdate,
    AccountToutiaoappCreate, AccountToutiaoappUpdate,
    AccountWebappCreate, AccountWebappUpdate,
    AccountWxappCreate, AccountWxappUpdate,
    AccountXzappCreate, AccountXzappUpdate
)

class CRUDAccountWechats(CRUDBase[AccountWechats, AccountWechatsCreate, AccountWechatsUpdate]):
    def get_by_uniacid(self, db: Session, *, uniacid: int) -> Optional[AccountWechats]:
        return self.get_by_field(db, "uniacid", uniacid)

class CRUDAccountAliapp(CRUDBase[AccountAliapp, AccountAliappCreate, AccountAliappUpdate]):
    def get_by_uniacid(self, db: Session, *, uniacid: int) -> Optional[AccountAliapp]:
        return self.get_by_field(db, "uniacid", uniacid)

class CRUDAccountBaiduapp(CRUDBase[AccountBaiduapp, AccountBaiduappCreate, AccountBaiduappUpdate]):
    def get_by_uniacid(self, db: Session, *, uniacid: int) -> Optional[AccountBaiduapp]:
        return self.get_by_field(db, "uniacid", uniacid)

class CRUDAccountPhoneapp(CRUDBase[AccountPhoneapp, AccountPhoneappCreate, AccountPhoneappUpdate]):
    def get_by_uniacid(self, db: Session, *, uniacid: int) -> Optional[AccountPhoneapp]:
        return self.get_by_field(db, "uniacid", uniacid)

class CRUDAccountToutiaoapp(CRUDBase[AccountToutiaoapp, AccountToutiaoappCreate, AccountToutiaoappUpdate]):
    def get_by_uniacid(self, db: Session, *, uniacid: int) -> Optional[AccountToutiaoapp]:
        return self.get_by_field(db, "uniacid", uniacid)

class CRUDAccountWebapp(CRUDBase[AccountWebapp, AccountWebappCreate, AccountWebappUpdate]):
    def get_by_uniacid(self, db: Session, *, uniacid: int) -> Optional[AccountWebapp]:
        return self.get_by_field(db, "uniacid", uniacid)

class CRUDAccountWxapp(CRUDBase[AccountWxapp, AccountWxappCreate, AccountWxappUpdate]):
    def get_by_uniacid(self, db: Session, *, uniacid: int) -> Optional[AccountWxapp]:
        return self.get_by_field(db, "uniacid", uniacid)

class CRUDAccountXzapp(CRUDBase[AccountXzapp, AccountXzappCreate, AccountXzappUpdate]):
    def get_by_uniacid(self, db: Session, *, uniacid: int) -> Optional[AccountXzapp]:
        return self.get_by_field(db, "uniacid", uniacid)

# 创建实例
account_wechats = CRUDAccountWechats(AccountWechats)
account_aliapp = CRUDAccountAliapp(AccountAliapp)
account_baiduapp = CRUDAccountBaiduapp(AccountBaiduapp)
account_phoneapp = CRUDAccountPhoneapp(AccountPhoneapp)
account_toutiaoapp = CRUDAccountToutiaoapp(AccountToutiaoapp)
account_webapp = CRUDAccountWebapp(AccountWebapp)
account_wxapp = CRUDAccountWxapp(AccountWxapp)
account_xzapp = CRUDAccountXzapp(AccountXzapp)